package com.huaqin.punan.sensor;

import java.util.List;

import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {
	private TextView my_tv;
	private Sensor mSensor;
	private SensorEvent mSensorEvent;
	private SensorManager mSensorManager;
	
	private String mSensorName = ""; 
	private String mSensorList = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		my_tv = (TextView)findViewById(R.id.my_tv);
		mSensorManager = (SensorManager)this.getSystemService(SENSOR_SERVICE);
		
		List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);        
        int size = sensorList.size();
        for (int i = 0; i<size ;i++) {            

        	int type = sensorList.get(i).getType();
        	switch(type){
        	//1 加速度传感器
        	case Sensor.TYPE_ACCELEROMETER:
        		mSensorName = "加速度传感器";
        		break;
        	//2 磁场传感器
        	case Sensor.TYPE_MAGNETIC_FIELD:
        		mSensorName = "磁场传感器";
        		break;
        	//3 方向感应器
        	case Sensor.TYPE_ORIENTATION:
        		mSensorName = "方向感应器";
        		break;
        	//4 陀螺仪传感器
        	case Sensor.TYPE_GYROSCOPE:
        		mSensorName = "陀螺仪传感器";
        		break;
        	//5 光传感器
        	case Sensor.TYPE_LIGHT:
        		mSensorName = "光传感器";
        		break;
        	//6 压力传感器
        	case Sensor.TYPE_PRESSURE:
        		mSensorName = "压力传感器";
        		break;
        	//7 温度传感器
        	case Sensor.TYPE_TEMPERATURE:
        		mSensorName = "温度传感器";
        		break;
        	//8 接近传感器
        	case Sensor.TYPE_PROXIMITY:
        		mSensorName = "接近传感器";
        		break;
        	//9 重力感应器
        	case Sensor.TYPE_GRAVITY:
        		mSensorName = "重力感应器";
        		break;
        	//10 线性加速度传感器
        	case Sensor.TYPE_LINEAR_ACCELERATION:
        		mSensorName = "线性加速度传感器";
        		break;
        	//11 旋转矢量传感器
        	case Sensor.TYPE_ROTATION_VECTOR:
        		mSensorName = "旋转矢量传感器";
        		break;
        	//12 相对湿度传感器
        	case Sensor.TYPE_RELATIVE_HUMIDITY:
        		mSensorName = "相对湿度传感器";
        		break;
        	//13 环境温度传感器
        	case Sensor.TYPE_AMBIENT_TEMPERATURE:
        		mSensorName = "环境温度传感器";
        		break;
        	//未知传感器
        	default:
        		mSensorName = "未知传感器";
        		break;
        	}
        	
            mSensor = sensorList.get(i);
            
            mSensorList += mSensor.getType()+". "+mSensorName+"\n"+mSensor.getName()+"\n";
               
        }
        
        my_tv.setText(mSensorList);
        
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
